package com.frxuexi.lib_base.utils

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.http.Const

@Interceptor(priority = 1, name = "登录拦截")
class ArouterInteceptor:IInterceptor {
    override fun init(context: Context?) {
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        if(arrayOf("/app/LoginActivity","/app/RegisterActivity","/app/FindPassActivity").contains(postcard?.path) || SPUtils.getInstance().getString(Const.TOKEN,"").isNotEmpty()){
            callback?.onContinue(postcard)
        }else{
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }
    }
}